<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="c"  uri="http://java.sun.com/jstl/core_rt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page isELIgnored="false" %>

<script type="text/javascript">
	dojo.require("dijit.TitlePane");
	dojo.require("dijit.Dialog");
    dojo.require("dijit.form.Button");
    dojo.require("dijit.form.TextBox");
    dojo.require("dijit.form.DateTextBox");
    dojo.require("dijit.form.TimeTextBox");
    dojo.require("dijit.form.ComboBox");
    
	function showDetails(strategicFileCode, tacticalFileCode , tacticalFileDesc, description, originalStartDate, originalEndDate, actualEndDate ){
 		
 		var productDetails = document.getElementById("productDetails");
 		productDetails.style.visibility="visible";
 		productDetails.innerHTML = "<h4>Zadanie: </h4>"+strategicFileCode+"."+tacticalFileCode+ " " +tacticalFileDesc+
 								   "<h4>Produkt: </h4>"+description+
 								   "<h4>Wykonanie: </h4><p style='margin-left: 3em;'>"+ originalStartDate +"<br/>"+originalEndDate+"<br/>"+actualEndDate+"<br/></p>";
 	}
	
	function edit(idProduct){
		
// 		request.setAttribute("idProduct" ,idProduct);
// 		alert("2");
		addEdit = dijit.byId("editDialog");
		addEdit.show();

// 		window.open('addEditProduct.html','','width=800,height=500, screenX=400, screenY=200 ');
	}
	function add(idProject){
		
		addEdit = dijit.byId("addDialog");
		addEdit.show();
	}
	function deleteProduct(){
		
		alert("Produkt został usunięty!");
	}
	
</script>

<h3><spring:message code="Product.title"/></h3>
<hr>
</br>
<div align="right">
	<button dojoType="dijit.form.Button"  onclick="deleteProduct()"><spring:message code="Product.delete"/></button>
</div>
<div style="overflow:auto; height: 500px;">
	<table class=productListTable>
		<tr>
			<th><spring:message code="Product.name"/></th>
			<th><spring:message code="Product.originalNumberOfDays"/></th>
			<th><spring:message code="Product.numberOfDays"/></th>
			<th><spring:message code="Product.actualEndDate"/></th>
			<th><spring:message code="Product.icon"/></th>
			<th class=tdSmall>   </th>
			<th class=tdSmall>   </th>
		</tr>
		<c:forEach var="project" items="${projectList}">
    	    <tr>
        		<td align="left">${project.strategicFileCode}.${project.tacticalFileCode} <br/> ${project.tacticalFileDesc} &nbsp ${project.strategicFileDesc}</td>
	     	    <td></td>
   		    	<td></td>
   		    	<td></td>
   		    	<td></td>
   		    	<td></td>
   		    	<td></td>
  	    	</tr>
  	    	<c:forEach var="product" items="${project.products}">
  	    		<tr onClick="showDetails('${project.strategicFileCode}', '${project.tacticalFileCode}', '${project.tacticalFileDesc}', '${product.description}', '${product.originalStartDate}','${product.originalEndDate}','${product.actualEndDate}')">
					<td>${product.description}</td>
					<td>${product.originalStartDate}</td>
					<td>${product.originalEndDate}</td>
					<td>${product.actualEndDate}</td>
					<td></td>
					<td><input id="${product.idProduct}" type="checkbox" /></td>
					<td><button dojoType="dijit.form.Button" ><img src="img/ico/common/edit_24.png" alt="edit" onclick="edit('${product.idProduct}')"></button></td>
				</tr>
  	    	</c:forEach>
  	    		<tr>
  	    			<td align="right"><button dojoType="dijit.form.Button" ><img src="img/ico/common/add_24.png" alt="add" onclick="add()"></button></td>
		     	    <td></td>
	   		    	<td></td>
	   		    	<td></td>
	   		    	<td></td>
	   		    	<td></td>
	   		    	<td></td>
  	    		</tr>
      	</c:forEach>
	</table>
</div>
<div dojoType="dijit.Dialog" id="editDialog" title="Edytuj Produkt" >	
<hr>

<h3><spring:message code="Product.title"/></h3>
<hr>
</br>
	<form:form id="product" method="post" action="productList.html" modelAttribute="product" >
		<table width="100%">
			<tr>
				<td>
				</td>
				<td>
					<form:label path="actualStartDate">
						<spring:message code="Product.latestStartDate"/>:
					</form:label>
				</td>
				<td>
					<form:label path="actualEndDate">
						<spring:message code="Product.endDate"/>: 
					</form:label>
				</td>
			</tr>
			<tr>
				<td>
					<select dojoType="dijit.form.ComboBox">
						<c:forEach var="project" items="${projectList}">
							<option>${project.strategicFileCode}.${project.tacticalFileCode} &nbsp ${project.tacticalFileDesc}</option>
	  					</c:forEach>
	  				</select>
<%-- 	  				<form:select path="projectList"> --%>
<%-- 				      	<form:option value="-" label="--Wybierz projekt--"/> --%>
<%-- 				      	<c:forEach var="project" items="${projectList}"> --%>
<%-- 				      		<form:options items="${project.tacticalFileCode}"/> --%>
<%-- 				      	</c:forEach>	 --%>
<%-- 				   </form:select> --%>
	  			</td>
				<td>
					<form:input dojoType="dijit.form.DateTextBox" path="actualStartDate" cssErrorClass="form-error-field"/>
				</td>
				<td>
					<form:input dojoType="dijit.form.DateTextBox" path="actualEndDate" cssErrorClass="form-error-field"/>
				</td>
			</tr></br>
			<tr>
				<td>
					<form:input dojoType="dijit.form.TextBox"  path="description" cssErrorClass="form-error-field"/>
				</td>
				<td>
					<form:input dojoType="dijit.form.TextBox"  path="details" cssErrorClass="form-error-field"/>
				</td>
				<td align="right">
					<button><spring:message code="Product.cancel"/></button>  <button type="submit" id="save"><spring:message code="Product.save"/></button>
				</td>
			</tr>
		</table>
	</form:form>
<hr>
</div>



	<div id="productDetails" title="Szczegóły produktu" style=" visibility: hidden;">
	</div>
